﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Pomelo.Data.MySql;
using Microsoft.EntityFrameworkCore;

namespace NetCoreTest.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            var context = new MySqlContext();
            var a=context.ConstConfig.Where(t => t.CKey == "LotteryRule").ToList(); ;
            return Content(a[0].CKey);
        }

        public IActionResult About()
        {
            ViewData["Message"] = "Your application description page.";
            var conn = new MySqlConnection("server=192.168.1.214;port=3306;User ID=net;Password=123456;database=net;Persist Security Info=false;Min Pool Size=2;Max Pool Size=2;Connect Timeout=30;");
            conn.Open();
            MySqlCommand msc = new MySqlCommand("select * from ConstConfig ", conn);
            var reader=msc.ExecuteReader();
            while (reader.Read()) {
                var s=reader[0].ToString();
            }
            conn.Close();

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View();
        }
    }
    public class MySqlContext : DbContext {
        public DbSet<ConstConfig> ConstConfig { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySql("server=192.168.1.214;port=3306;User ID=net;Password=123456;database=net;Persist Security Info=false;Min Pool Size=2;Max Pool Size=2;Connect Timeout=30;");
        }
    }
}
